#!/usr/bin/perl -w

# Return 0 if the required VM is support on this local
# machine, and 1+stderr if not. This will be called via
# Cluster request daemon request "vm_check type=virsh" usually.

@P=qw(/usr/bin /usr/sbin /usr/local/bin /bin /sbin /opt/bin);

$VBoxManage=undef;
for (@P) {
	if(-f "$_/VBoxManage" && -x _) {
		$VBoxManage="$_/VBoxManage";last;
	}
}

if(!defined($VBoxManage)) {
	print STDERR "VBoxManage executable not found.\n";
	exit(1);
}

# Even if we do find it we need to check it runs correctly.

$r=`$VBoxManage --version 2>&1`;
if($?>>8) {
	print STDERR "VBoxManage --version command returned error.\n";
	print STDERR $r;
	exit(1);
}

# Check that the output indicates everything is ok

# if($r !~ /Running hypervisor:/) {
	# print STDERR "virsh version not returning hypervisor information.\n";
	# exit(1);
# }

exit(0); # Yup - VBoxManage appears to be supported
